package com.qf.controller;

import com.qf.entity.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
// 注意：写路径的时候，不要写大写字母，因为有浏览器会自动转换 大小写导致 404 错误
@RequestMapping("/p")
public class ParamController {

    /**
     * 路径收参
     * @param id
     * @return
     */
    @RequestMapping("/get/{id}")
    public String test4(@PathVariable("id") Integer id){
        System.out.println(id);
        return "ok";
    }

    @RequestMapping("/get/{id}/{name}")
    public String test5(@PathVariable("id") Integer id,@PathVariable("name") String name,Integer age ){
        System.out.println(id);
        System.out.println(name);
        System.out.println(age);
        return "ok";
    }


    /**
     * 数组收参
     * @param hobby
     * @return
     */
    @RequestMapping("/test3")
    public String test3(String[] hobby){
        for (String s : hobby) {
            System.out.println(s);
        }
        return "ok";
    }

    /**
     * 实体收参
     * http://localhost:8080/p/test2?id=100&name=lisi&gender=true&birth=1990-01-01
     * @param user
     * @return
     */
    @RequestMapping("/test2")
    public String test2(User user){
        System.out.println(user);
        return "ok";
    }

}
